package com.cmc6.notify.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cmc6.common.model.dto.NotEmptyIdSet;
import com.cmc6.common.model.dto.NotNullId;
import com.cmc6.common.util.ApiResult;
import com.cmc6.notify.model.dto.NotifyPageDTO;
import com.cmc6.notify.model.vo.NotifyInfoByIdVO;
import com.cmc6.notify.model.vo.NotifyPageVO;
import com.cmc6.notify.service.NotifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/notify")
@Api(tags = "通知控制器")
public class NotifyController {

    @Resource
    NotifyService baseService;

    @ApiOperation(value = "分页排序查询：当前用户，通知")
    @PostMapping("/userPage")
    public ApiResult<Page<NotifyPageVO>> userPage(@RequestBody @Valid NotifyPageDTO dto) {
        return ApiResult.ok(baseService.userPage(dto));
    }

    @ApiOperation(value = "当前用户：已读通知")
    @PostMapping("/userRead")
    public ApiResult<String> userRead(@RequestBody @Valid NotEmptyIdSet notEmptyIdSet) {
        return ApiResult.ok(baseService.userRead(notEmptyIdSet));
    }

    @ApiOperation(value = "当前用户：全部已读")
    @PostMapping("/userAllRead")
    public ApiResult<String> userAllRead() {
        return ApiResult.ok(baseService.userAllRead());
    }

    @ApiOperation(value = "获取：当前用户，未读通知总和")
    @PostMapping("/userNoReadCount")
    public ApiResult<Long> userNoReadCount() {
        return ApiResult.ok(baseService.userNoReadCount());
    }

    @ApiOperation(value = "通过主键id，查看详情")
    @PostMapping("/infoById")
    public ApiResult<NotifyInfoByIdVO> infoById(@RequestBody @Valid NotNullId notNullId) {
        return ApiResult.ok(baseService.infoById(notNullId));
    }

}
